using System.Collections.Generic;
using System.Collections.ObjectModel;
using T4UtilityBelt.DataDesigns;

namespace T4UtilityBelt.UxDesigns.Styles
{
    public class StyleCollection : ObservableCollection<Style>
    {
        public StyleCollection()
        {
            _propertiesByName = new Dictionary<string, Style>();
        }

        private readonly Dictionary<string, Style> _propertiesByName;

        public Style this[string index]
        {
            get
            {
                return _propertiesByName[index];
            }
        }

        protected override void ClearItems()
        {
            base.ClearItems();
            _propertiesByName.Clear();
        }

        protected override void RemoveItem(int index)
        {
            Style item = this[index];
            _propertiesByName.Remove(item.Name);
            base.RemoveItem(index);
        }

        protected override void InsertItem(int index, Style item)
        {
           _propertiesByName.Add(item.Name, item);
            base.InsertItem(index, item);
        }

        protected override void SetItem(int index, Style item)
        {
            _propertiesByName.Add(item.Name, item);
            base.SetItem(index, item);
        }
    }
}